<?php

namespace App\Models;

use Dcat\Admin\Traits\HasDateTimeFormatter;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Dcat\Admin\Traits\ModelTree;
class Author extends Model
{
	use HasDateTimeFormatter,ModelTree;

//	public function goods(){
//	    return $this->hasMany(Goods::class);
//    }
    //所属作家
    // 排序字段名称，默认值为 order
    protected $orderColumn = 'order_number';
    public function goods():BelongsToMany
    {
        $pivotTable = 'author_good'; // 中间表

        $relatedModel = Goods::class; // 关联模型类名

        return $this->belongsToMany($relatedModel, $pivotTable, 'author_id', 'good_id');
//        return $this->belongsToMany(Author::class);
    }

    public function onlineExhibition():BelongsToMany {
        $pivotTable = 'online_exhibition_authors'; // 中间表

        $relatedModel = OnlineExhibition::class; // 关联模型类名

        return $this->belongsToMany($relatedModel, $pivotTable, 'author_id', 'online_exhibition_id');
    }
}
